import * as echarts from '../../ec-canvas/echarts';
import {
  request
} from '../../request/index.js'

function initChart(canvas, width, height) {
  const chart = echarts.init(canvas, null, {
    width: width,
    height: height
  });
  canvas.setChart(chart);

  var option = {
      title: {
        text: 'ECharts 入门示例'
      },
      tooltip: {},
      legend: {
        data: ['销量']
      },
      xAxis: {
        type: 'category',
        data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun']
    },
    yAxis: {
        type: 'value'
    },
    series: [{
        data: [820, 932, 901, 934, 1290, 1330, 1320],
        type: 'line'
    }]
  };
  chart.setOption(option);
  return chart;
}

Page({
  data: {
    ec: {
      //onInit: initChart,如果在wxml中没有写bind:init方法，就直接这样用
      onInit: initChart
    }
  },
  echartInit(e) {
    console.log(e);
    initChart(e.detail.canvas, e.detail.width, e.detail.height);
  },
  onLoad: function () {
    // request({
    //   url: '',
    //   data: {}
    // }).then(r => {
    //   console.log(r);
    //   // 填入数据
    // })
  }
});